package com.zmh.wt.healthmonitor.controller;


import com.zmh.wt.healthmonitor.mqtt.MQTTClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;


@RestController
//@RequestMapping("/mh/mqtt")
public class MqttControler {

    @Autowired
    MQTTClient MQTTClient;

    //下面都是测试所用，实际工程中不需要这个界面
//    @Value("publish")
//    String topic;
//    Queue<String> msgQueue = new LinkedList<>();
//    int count = 1;

//    @PostMapping("/getMsg")
//    @ResponseBody
//    public synchronized void mqttMsg(MqttMssg mqttMssg) throws UnsupportedEncodingException {
//        System.out.println("队列元素数量：" + msgQueue.size());
//        System.out.println("***************" + mqttMssg.getFeature1() + ":" + mqttMssg.getFeature2() + "****************");
//
////      时间格式化
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String time = df.format(new Date());
//        count++;
//
////      map转json
//        JSONObject json = JSONObject.fromObject(mqttMssg);
//        String sendMsg = json.toString();
//        System.out.println(sendMsg);
//
////        队列添加元素
//        boolean flag = msgQueue.offer(sendMsg);
//        if (flag) {
//            //发布消息  topic2 是你要发送到那个通道里面的主题 比如我要发送到topic2主题消息
//            myMQTTClient.publish(msgQueue.poll(), topic);
//            System.out.println("时间戳" + System.currentTimeMillis());
//        }
//        System.out.println("队列元素数量：" + msgQueue.size());
//    }
}